package com.hzsai.controller;

import com.alibaba.fastjson.JSON;
import com.hzsai.service.StudentService;
import com.hzsai.utils.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * hzsai 2019/8/17
 * usage:
 **/
@Api(tags = "mybatis-第3课")
@RequestMapping("/student")
@RestController
public class StudentController {

    @Autowired
    private StudentService service;

    @ApiOperation(value = "查询信息", notes = "根据班级id查询学生信息")
    @GetMapping("/find/{id}")
    ResultMsg findById(@PathVariable Integer id) {
        //JSON.toJSON(service.findById(id))
        return ResultMsg.success(service.findById(id));
    }

    @ApiOperation(value = "查询信息", notes = "根据学生id查询班级信息")
    @GetMapping("/get/{id}")
    ResultMsg getById(@PathVariable Integer id) {
        return ResultMsg.success(service.getById(id));
    }

    @ApiOperation(value = "查询学生课程信息", notes = "根据学生id查询")
    @GetMapping("/getCourse/{id}")
    ResultMsg getCourseById(@PathVariable Integer id) {
        return ResultMsg.success(service.getCourseById(id));
    }

    @ApiOperation(value = "查询课程所有学生", notes = "根据课程id来查询")
    @GetMapping("getStudent/{id}")
    ResultMsg getStudentById(@PathVariable Integer id) {
        return ResultMsg.success(service.getStudentById(id));
    }
}
